<template>
  <div>
    <el-form :inline="true" :model="listagency" >
      <el-form-item label="客户名称">
        <el-input v-model="listcom.nickname" />
      </el-form-item>
      <el-form-item label="电话：">
        <el-input v-model="listcom.phone" />
      </el-form-item>
      <el-button type="primary" plain @click="findall()" style="margin-bottom: 20px">搜索</el-button>
    </el-form>




  </div>



  <el-table :data="tableData" style="width: 100%">
    <el-table-column prop="id" label="用户id" width="130" />
<!--    <el-table-column prop="status" label="状态" width="130" />-->
    <el-table-column prop="nickname" label="昵称" width="130" />
    <el-table-column prop="phone" label="电话" width="130" />
    <el-table-column prop="avatar" label="头像" width="130" v-slot="scope">
      <img :src="scope.row.avatar" alt="" style="width: 50px; height: 50px" />
    </el-table-column>
    <el-table-column prop="status" label="状态" v-slot="scope" width="130">
      <template v-if="scope.row.status == 1"> 冻结 </template>
      <template v-if="scope.row.status == 0"> 正常 </template>
    </el-table-column>
    <el-table-column prop="createTime" label="创建时间" width="180" />

    <el-table-column label="操作" width="200">
      <template #default="scope">
        <el-button @click="dongjie1(scope.row)" type="text" size="small" class="action-button" v-if="scope.row.status == 0">冻结</el-button>
        <el-button @click="huifu(scope.row)" type="text" size="small" class="action-button" v-if="scope.row.status == 1">恢复</el-button>
      </template>
    </el-table-column>
  </el-table>


  <el-pagination
    v-model:current-page="listcom.pageNum"
    v-model:page-size="listcom.pageSize"
    :page-sizes="[5, 10, 15, 20]"
    layout="total, sizes, prev, pager, next, jumper"
    :total="total"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>
<script setup>
//查询服务
import {ref} from "vue";
import {dongjie, getcomm} from "@/api/cutsom/custom";
import {ElMessage} from "element-plus";


//查看客户列表
const tableData = ref([]);
const total=ref(0)
const listcom=ref({
  pageNum:1,
  pageSize:5,
  nickname:'',
  phone:''
})
const handleSizeChange = (val) => {
  listcom.value.pageSize=val
  findall()
}
const handleCurrentChange = (val) => {
  listcom.value.pageNume=val
  findall()
}
function findall() {
  getcomm(listcom.value).then((res) => {
    console.log(res)
    tableData.value = res.data.data.records;
    total.value=res.data.data.total;
    console.log(res.data.data);
  });
}
findall();

//冻结
const dongjie1 = (row) => {
  dongjie(row.id).then((res) => {
    if (res.data.code == 200) {
      ElMessage.success('冻结成功');
      findall();
    } else {
      ElMessage.error('冻结失败');
    }
  });
};
//恢复
const huifu = (row) => {
  dongjie(row.id).then((res) => {
    console.log(res+"哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈或")
    if (res.data.code == 200) {
      ElMessage.success('恢复成功');
      findall();
    } else {
      ElMessage.error('恢复失败');
    }
  });
};




</script>
